import json
import os.path


class TSettings :
    def __init__(self):
        self.settingsFn = ""
        self.info = {
            "server":{
                "host":"0.0.0.0",
                "port":2000
            }
        }
    def loadByFn(self , fn):
        try:
            if os.path.exists(fn):
                self.settingsFn = fn
                with open(fn , 'r' , encoding='utf-8') as f :
                    try:
                        c = f.read()
                        self.info = json.loads(c)
                    except Exception as err:
                        print('load settings fail.',err)
        except Exception as er:
            print(er)
settings = TSettings()